package chartor;

import java.awt.Point;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

public class Player extends Rectangle {
	private String nameString;
	private float health;
	public final float HEALTH = 100;
	private boolean a;// a键状态
	private boolean s;// s键状态
	private boolean d;// d键状态
	private boolean w;// w键状态
	private int speed = 2;// 移动速度
	private boolean shift;// 加速移动
	private boolean j;// 射击键
	private boolean r;// 装弹
	private int[] num = new int[8];
	private Gun classes;// 武器种类
	public Point targetPoint;// 鼠标位置、
	private boolean num1;// 数字键1
	private int gotnumer;
	private int direction=1;//方向
	public int targetpoint_x=0;
	public int targetpoint_y=0;
	/**
	 * 是否达到边界
	 */
	public boolean arrive;
	public boolean isNum1() {
		return num1;
	}

	public void setNum1(boolean num1) {
		this.num1 = num1;
	}

	public boolean isNum2() {
		return num2;
	}

	public void setNum2(boolean num2) {
		this.num2 = num2;
	}

	public boolean isNum3() {
		return num3;
	}

	public void setNum3(boolean num3) {
		this.num3 = num3;
	}

	private boolean num2;
	private boolean num3;
	private List<Gun> guns = new ArrayList<Gun>();

	public Player(int x, int y, String nameString, boolean a, boolean s, boolean d, boolean w) {
		super();
		this.x = x;
		this.y = y;
		this.nameString = nameString;
		this.a = a;
		this.s = s;
		this.d = d;
		this.w = w;
		this.health = 100;
		this.width = 40;
		this.height = 40;
		this.setJ(false);
		this.guns.add(new Chongfeng(this));
		this.guns.add(new JUJI(this));
		this.guns.add(new XianDan(this));
		this.classes = this.guns.get(0);
	}

	public List<Gun> getGuns() {
		return guns;
	}


	public void setGuns(List<Gun> guns) {
		this.guns = guns;
	}

	/**
	 * 射击
	 */
	public void tututu(int d, Point p) {// 状态 方向 后坐力 子弹种类
		getClasses().tututu(d, p);
		int xp=Math.abs(p.x-this.x);
		int yp=Math.abs(p.y-this.y);
		if(xp>yp) {
			if(p.x>this.x)
				this.direction=3;
			else {
				this.direction=1;
			}
		}else {
			if(p.y>this.y)
				this.direction=2;
			else {
				this.direction=4;
			}
		}
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + ((nameString == null) ? 0 : nameString.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		Player other = (Player) obj;
		if (nameString == null) {
			if (other.nameString != null)
				return false;
		} else if (!nameString.equals(other.nameString))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "Player [x=" + x + ", y=" + y + ", nameString=" + nameString + ", a=" + a + ", s=" + s + ", d=" + d
				+ ", w=" + w + "]";
	}

	public boolean isA() {
		return a;
	}

	public void setA(boolean a) {
		this.a = a;
	}

	public boolean isS() {
		return s;
	}

	public void setS(boolean s) {
		this.s = s;
	}

	public boolean isD() {
		return d;
	}

	public void setD(boolean d) {
		this.d = d;
	}

	public boolean isW() {
		return w;
	}

	public void setW(boolean w) {
		this.w = w;
	}

	public double getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public double getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

	public String getNameString() {
		return nameString;
	}

	public void setNameString(String nameString) {
		this.nameString = nameString;
	}

	private void move(int dir) {
		if (getClasses() instanceof JUJI || getClasses() instanceof XianDan) {
			speed = 1;
		} else if (getClasses() instanceof Chongfeng) {
			speed = 2;
		}
		switch (dir) {
		case 1:
			this.x -= speed;
			if(!isJ())
			setDirection(1);
			break;
		case 2:
			this.y += speed;
			if(!isJ())
			setDirection(2);
			break;
		case 3:
			this.x += speed;
			if(!isJ())
			setDirection(3);
			break;
		case 4:
			this.y -= speed;
			if(!isJ())
			setDirection(4);
			break;
		default:
			break;
		}
	}

	private void run(int dir) {
		if (getClasses() instanceof JUJI || getClasses() instanceof XianDan) {
			speed = 1;
		} else if (getClasses() instanceof Chongfeng) {
			speed = 2;
		}
		switch (dir) {
		case 1:
			this.x -= speed + 1;
			if(!isJ())
			setDirection(1);
			
			break;
		case 2:
			this.y += speed + 1;
			if(!isJ())
			setDirection(2);
			break;
		case 3:
			this.x += speed + 1;
			if(!isJ())
			setDirection(3);
			break;
		case 4:
			this.y -= speed + 1;
			if(!isJ())
			setDirection(4);
			break;
		default:
			break;
		}
	}

	public void adnum(int n) {
		this.num[n] += 4;
	}

	public void Mont() {
		for (int i = 0; i < num.length; i++) {
			if (i >= 4 && num[i] != 0) {
				num[i]--;
				this.run(i - 3);
			} else if (num[i] != 0) {
				num[i]--;
				this.move(i + 1);
			}
		}
	}

	public boolean isShift() {
		return shift;
	}

	public void setShift(boolean shift) {
		this.shift = shift;
	}

	public float getHealth() {
		return health;
	}

	public void setHealth(float health) {
		this.health = health;
	}

	public boolean isJ() {
		return j;
	}

	public void setJ(boolean j) {
		this.j = j;
	}

	public Gun getClasses() {
		return classes;
	}

	public void setClasses(Gun classes) {
		this.classes = classes;
	}

	public boolean isR() {
		return r;
	}

	public void setR(boolean r) {
		this.r = r;
	}

	public int getGotnumer() {
		return gotnumer;
	}

	public void setGotnumer(int gotnumer) {
		this.gotnumer = gotnumer;
	}

	public int getDirection() {
		return direction;
	}

	public void setDirection(int direction) {
		this.direction = direction;
	}
}
